home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / v7n21.arc / READ123.BAS < prev    next >
BASIC Source File  |  1988-11-14  |  4KB  |  114 lines

  1. '********** READ123.BAS
  2. 'Copyright (c) 1988, Ziff Communications Co.
  3. 'PC Magazine * Ethan Winer * Martin Valley 
  4. 'Reads a file written by Lotus 123
  5.  
  6. DEFINT A-Z
  7. DECLARE SUB GetFormat (Format, Row, Column)
  8.  
  9. DIM SHARED FileNum                      'the file number to use
  10. DIM SHARED CellFmt AS STRING * 1        'allows reading one byte
  11.  
  12. CLS
  13. DO
  14.    INPUT "Enter name of Lotus file to read: ", FileName$
  15.    IF FileName$ = "" THEN FILES "*.WK?"
  16. LOOP UNTIL LEN(FileName$)
  17.  
  18. FileNum = FREEFILE                      'obtain the next available file handle
  19. OPEN FileName$ FOR BINARY AS #FileNum   'open the file for Binary access
  20.  
  21. DO UNTIL Opcode = 1                     'until the Lotus "End of File" Opcode
  22.  
  23.    GET FileNum, , Opcode        'get the next opcode
  24.    GET FileNum, , Length        'and the length of the data that follows
  25.  
  26.    SELECT CASE Opcode           'handle the data according to its type
  27.  
  28.       CASE 0                    'Beginning of file record (and version)
  29.      GET FileNum, , Integ   'Integ holds the version number
  30.  
  31.      IF Integ < 1028 OR Integ > 1030 THEN   'test this if you want
  32.         PRINT "NOT a Lotus File !"
  33.         END
  34.      END IF
  35.  
  36.      PRINT "BOF:  Lotus ";          'Version number is the only
  37.      SELECT CASE Integ              '  information in this record
  38.          CASE 1028
  39.         PRINT "123 version 1.0 or 1A"
  40.          CASE 1029
  41.         PRINT "Symphony version 1.0"
  42.          CASE 1030
  43.         PRINT "123 version 2.0, 2.1, or Symphony version 1.1"
  44.      END SELECT
  45.  
  46.       CASE 12                   'Blank - NOTE: Lotus saves blank cells only
  47.                 '  if they are formatted or protected
  48.      GetFormat Format, Row, Column
  49.      PRINT "Blank:  "; Format, "Row ="; Row, "Col ="; Column
  50.  
  51.       CASE 13                   'Integer
  52.      GetFormat Format, Row, Column
  53.      GET FileNum, , Integ
  54.      PRINT "Integer:"; Format, "Row ="; Row, "Col ="; Column, Integ
  55.  
  56.       CASE 14                   'Real number (BASIC double precision type)
  57.      GetFormat Format, Row, Column
  58.      GET FileNum, , Number#
  59.      PRINT "Number: "; Format, "Row ="; Row, "Col ="; Column, Number#
  60.      
  61.       CASE 15                   'Label
  62.      GetFormat Format, Row, Column
  63.      Info$ = SPACE$(Length - 6)     'create a string to hold the label
  64.                     '6 is subtracted to exclude the
  65.                     '  Format, Column, Row, and 0 bytes
  66.                     '  that were included in the original
  67.                     '  length byte (already gotten by the
  68.                     '  GetFormat routine)
  69.      GET FileNum, , Info$           'get the label text
  70.      GET FileNum, , CellFmt$        'gobble up the trailing CHR$(0) byte
  71.      PRINT "Label:  "; Format, "Row ="; Row, "Col ="; Column, Info$
  72.  
  73.  
  74.       CASE 16                   'Formula
  75.      GetFormat Format, Row, Column
  76.      GET FileNum, , Number#         'get the cell's value
  77.      GET FileNum, , Length          'get length of formula "text"
  78.      SEEK FileNum, SEEK(FileNum) + Length   'skip over the formula
  79.                     'the formula is "tokenized" in reverse
  80.                     'Polish notation - not a pretty story
  81.      PRINT "Formula:"; Format, "Row ="; Row, "Col ="; Column, Number#
  82.  
  83.       CASE ELSE                 'anything else merely relates to the way the
  84.                 '  spreadsheet operates (recalc order, print
  85.                 '  ranges, and so forth)
  86.      Dummy$ = SPACE$(Length)        'skip over the unwanted record
  87.      GET FileNum, , Dummy$
  88.      PRINT "Opcode: "; Opcode       'show its Opcode just for fun
  89.  
  90.    END SELECT
  91.  
  92.    IF CSRLIN > 21 THEN
  93.       PRINT : PRINT "Press <ESC> to end or any other key for more . . ."
  94.       DO: K$ = INKEY$: LOOP UNTIL LEN(K$)
  95.       IF K$ = CHR$(27) THEN EXIT DO
  96.       CLS
  97.    END IF
  98.  
  99.    Cntr = Cntr + 1
  100.  
  101. LOOP
  102.  
  103.    PRINT "Number of Records Processed ="; Cntr
  104.  
  105. CLOSE
  106.  
  107. SUB GetFormat (Format, Row, Column)
  108.      
  109.       GET FileNum, , CellFmt$: Format = ASC(CellFmt$)
  110.       GET FileNum, , Column
  111.       GET FileNum, , Row
  112.  
  113. END SUB
  114.